package com.lovo.service.impl;

import com.lovo.dao.IStudentDAO;
import com.lovo.model.CourseDO;
import com.lovo.model.InfoDO;
import com.lovo.model.StudentDO;
import com.lovo.model.StudentDTO;
import com.lovo.service.IStudentService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * Description:
 *
 * @author LiuChengQi
 * @date Created on 2020/11/18
 */
@Service
@Transactional
public class StudentService implements IStudentService {
    @Resource
    private IStudentDAO dao;


    @Override
    public List<StudentDTO> listAllStudent() {
        List<StudentDO> all = dao.findAll();
        List<StudentDTO> studentDTOS = new ArrayList<>();
        for (StudentDO s:all) {
            StudentDTO res = new StudentDTO();
            List<CourseDO> courseDOList = s.getCourseDOList();
            System.out.println(courseDOList);
            List<InfoDO> infoDOS = s.getInfoDOS();
            System.out.println(infoDOS);
            res.setStudentDO(s);
            studentDTOS.add(res);
        }
        return studentDTOS;
    }

    @Override
    public StudentDO findbyid(Long id) {
        return dao.findById(id).orElse(null);
    }

    @Override
    public void save(StudentDO studentDO) {
        dao.save(studentDO);
    }

    @Override
    public void del(Long id) {
        dao.deleteById(id);
    }

    @Override
    public void update(StudentDO studentDO) {
        dao.save(studentDO);
    }

}
